﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;
//using Microsoft.Expression.Interactivity.Core;

namespace SilverlightDebateViewModel
{
    public class SelectFirstListBoxItem : TargetedTriggerAction<FrameworkElement>
	{
		public SelectFirstListBoxItem()
		{
		}

		protected override void OnAttached()
		{
			base.OnAttached();
		}

		protected override void OnDetaching()
		{
			base.OnDetaching();
		}

        protected override void Invoke(object parameter)
        {
            ListBox lb = AssociatedObject as ListBox;
            if (lb != null && lb.Items.Count > 0)
            {
                lb.SelectedIndex = 0;
                return;
            }
            ComboBox cbo = AssociatedObject as ComboBox;
            if (cbo != null && cbo.Items.Count > 0)
            {
                cbo.SelectedIndex = 0;
                return;
            }
        }

	}
}